package com.xh.rabbit_pay.listener;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 监听死信队列，用于取消订单
 */
@Component
public class MyCancelListener implements ChannelAwareMessageListener {

    @RabbitListener(queues = "q.dlx", ackMode = "MANUAL")
    public void onMessage(Message message, Channel channel) throws IOException {
        String payId = new String(message.getBody());
        System.out.println("取消订单：" + payId);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
